package logic

import (
	"context"
	"eight-dimensional-mall/goods_srv/goods"

	"eight-dimensional-mall/api/internal/svc"
	"eight-dimensional-mall/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCartListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartListLogic {
	return &CartListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CartListLogic) CartList(req *types.CartListRequest) (resp *types.Response, err error) {
	res, err := l.svcCtx.GoodsSrv.CartList(l.ctx, &goods.CartListReq{UserId: 1})
	if err != nil {
		return &types.Response{
			Code: -1,
			Msg:  "列表展示失败",
			Data: nil,
		}, nil
	}

	return &types.Response{
		Code: 0,
		Msg:  "列表展示成功",
		Data: map[string]interface{}{
			"car_list": res.CartList,
		},
	}, nil
}
